package TestFiles;
import graphdisplay.AbstractGraph;
import graphdisplay.Graph;
import graphdisplay.GraphView;
import graphdisplay.WeightedEdge;
import graphdisplay.WeightedGraph;

import java.awt.Container;
import java.awt.GridLayout;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;

import TestFiles.DisplayUSMap.City;

public class TestShortestPath {
	  int strnode;
	  int endnode;
  public TestShortestPath(int u, int v) throws FileNotFoundException {
		// TODO Auto-generated constructor stub
	  System.out.println("dgfdg"+u+v);
	this.strnode=u;
	  this.endnode=v;
	////////////////
	  
	  List<City> verticeslist = new ArrayList<City>();


      verticeslist.add(new City("Seattle", 75, 50));
      verticeslist.add(new City("San Francisco", 50, 210));
      verticeslist.add(new City("Los Angeles", 75, 275));
      verticeslist.add(new City("Denver", 275, 175));
      verticeslist.add(new City("Kansas City", 400, 245));
      verticeslist.add(new City("Chicago", 450, 100));
      verticeslist.add(new City("Boston", 700, 80));
      verticeslist.add(new City("New York", 675, 120));
      verticeslist.add(new City("Atlanta", 575, 295));
      verticeslist.add(new City("Miami", 600, 400));
      verticeslist.add(new City("Dallas", 408, 325));
      verticeslist.add(new City("Houston", 450, 360));
	  
	  
	
      List<WeightedEdge> edgeslist = new ArrayList<WeightedEdge>();
      // Edge array for graph in Figure 27.1
      edgeslist.add(new WeightedEdge(0, 1,807));
      edgeslist.add(new WeightedEdge(0, 3,1331));
      edgeslist.add(new WeightedEdge(0, 5,2097));

      edgeslist.add(new WeightedEdge(1, 0,807));
      edgeslist.add(new WeightedEdge(1, 2,381));
      edgeslist.add(new WeightedEdge(1, 3,1267));

      edgeslist.add(new WeightedEdge(2, 1,381));
      edgeslist.add(new WeightedEdge(2, 3,1015));
      edgeslist.add(new WeightedEdge(2, 4,1663));
      edgeslist.add(new WeightedEdge(2, 10,1435));

      edgeslist.add(new WeightedEdge(3, 0,1331));
      edgeslist.add(new WeightedEdge(3, 1,1267));
      edgeslist.add(new WeightedEdge(3, 2,1015));
      edgeslist.add(new WeightedEdge(3, 4,599));
      edgeslist.add(new WeightedEdge(3, 5,1003));

      edgeslist.add(new WeightedEdge(4, 2,1663));
      edgeslist.add(new WeightedEdge(4, 3,599));
      edgeslist.add(new WeightedEdge(4, 5,533));
      edgeslist.add(new WeightedEdge(4, 7,1260));
      edgeslist.add(new WeightedEdge(4, 8,864));
      edgeslist.add(new WeightedEdge(4, 10,496));

      edgeslist.add(new WeightedEdge(5, 0,2097));
      edgeslist.add(new WeightedEdge(5, 3,1003));
      edgeslist.add(new WeightedEdge(5, 4,533));
      edgeslist.add(new WeightedEdge(5, 6,983));
      edgeslist.add(new WeightedEdge(5, 7,787));

      edgeslist.add(new WeightedEdge(6, 5,983));
      edgeslist.add(new WeightedEdge(6, 7,214));

      edgeslist.add(new WeightedEdge(7, 4,1260));
      edgeslist.add(new WeightedEdge(7, 5,787));
      edgeslist.add(new WeightedEdge(7, 6,214));
      edgeslist.add(new WeightedEdge(7, 8,888));

      edgeslist.add(new WeightedEdge(8, 4,864));
      edgeslist.add(new WeightedEdge(8, 7,888));
      edgeslist.add(new WeightedEdge(8, 9,661));
      edgeslist.add(new WeightedEdge(8, 10,781));
      edgeslist.add(new WeightedEdge(8, 11,810));

      edgeslist.add(new WeightedEdge(9, 8,661));
      edgeslist.add(new WeightedEdge(9, 11,1187));

      edgeslist.add(new WeightedEdge(10, 2,1435));
      edgeslist.add(new WeightedEdge(10, 4,496));
      edgeslist.add(new WeightedEdge(10, 8,781));
      edgeslist.add(new WeightedEdge(10, 11,239));

      edgeslist.add(new WeightedEdge(11, 8,810));
      edgeslist.add(new WeightedEdge(11, 9,1187));
      edgeslist.add(new WeightedEdge(11, 10,239));

	  
      //////////////
	  
	
    String[] vertices = {"0.Seattle", "1.San Francisco", "2.Los Angeles",
      "3.Denver", "4.Kansas City", "5.Chicago", "6.Boston", "7.New York",
      "8.Atlanta", "9.Miami", "10.Dallas", "11.Houston"};

	/*  int[][] edges = {
	    {0, 1, 807}, {0, 3, 1331}, {0, 5, 2097},
	    {1, 0, 807}, {1, 2, 381}, {1, 3, 1267},
	    {2, 1, 381}, {2, 3, 1015}, {2, 4, 1663}, {2, 10, 1435},
	    {3, 0, 1331}, {3, 1, 1267}, {3, 2, 1015}, {3, 4, 599}, 
	      {3, 5, 1003},
	    {4, 2, 1663}, {4, 3, 599}, {4, 5, 533}, {4, 7, 1260},
	      {4, 8, 864}, {4, 10, 496},
	    {5, 0, 2097}, {5, 3, 1003}, {5, 4, 533}, 
	      {5, 6, 983}, {5, 7, 787},
	    {6, 5, 983}, {6, 7, 214},
	    {7, 4, 1260}, {7, 5, 787}, {7, 6, 214}, {7, 8, 888},
	    {8, 4, 864}, {8, 7, 888}, {8, 9, 661}, 
	      {8, 10, 781}, {8, 11, 810},
	    {9, 8, 661}, {9, 11, 1187},
	    {10, 2, 1435}, {10, 4, 496}, {10, 8, 781}, {10, 11, 239},
	    {11, 8, 810}, {11, 9, 1187}, {11, 10, 239}
	  };*/
	  

	  

    WeightedGraph<String> graph1 = 
      new WeightedGraph<String>(edgeslist, 12);
    System.out.println("Enter the Starting node to find shortest path:" );
    //int startnodes = scan.nextInt();
    System.out.print("Enter the Destination node to find the shortest path:");
    //int endnodes = scan.nextInt();
 
    WeightedGraph<String>.ShortestPathTree tree1 = 
    		 // graph1.getShortestPath(startnodes);
   graph1.getShortestPath(endnode);

    tree1.printAllPaths();

    // Display shortest paths from Houston to Chicago
    System.out.print("Shortest path from Houston to Chicago: ");
    java.util.List<Integer> path = tree1.getPath1(strnode);
   
    for (int i = 0; i < path.size(); i++){
    	System.out.print(path.get(i));
    }
    //java.util.List<String> path = tree1.getPath(NewJFrame.v);

   /*for (String s: path) 
    {
     System.out.print(s + " gg ");
     
    }*/
 
    
    
   /* NextPage page = new NextPage();
    page.setTitle("Shortest Node");
    Container content = page.getContentPane();
                   content.setLayout(new GridLayout(1, 1));
                   page.setVisible(true);
                   Border border = LineBorder.createGrayLineBorder();
    JLabel label1 = new JLabel();                      
                   label1.setHorizontalTextPosition(JLabel.CENTER);
                   label1.setVerticalTextPosition(JLabel.BOTTOM);
                   label1.setBorder(border);

                   JLabel label2 = new JLabel();
                   label2.setHorizontalTextPosition(JLabel.LEFT);
                   label2.setVerticalTextPosition(JLabel.TOP);
                   label2.setBorder(border);
    ArrayList<String> searchOrders = new ArrayList<String>();
    for (int i = 0; i < path.size(); i++){
                        //   searchOrders.add((String)path.get(i));
    	System.out.print(path.get(i).toString() + " ");
                           if(i!=path.size()-1)
                           {                        
                        	   //searchOrders.add("-------->");
                        	   }
                   }
                   //label2.setText(searchOrders.toString());
                   content.add(label2);*/
   /* edges = new int[][]{
      {0, 1, 2}, {0, 3, 8}, 
      {1, 0, 2}, {1, 2, 7}, {1, 3, 3},
      {2, 1, 7}, {2, 3, 4}, {2, 4, 5},
      {3, 0, 8}, {3, 1, 3}, {3, 2, 4}, {3, 4, 6},
      {4, 2, 5}, {4, 3, 6}
    };
    WeightedGraph<Integer> graph2 = 
      new WeightedGraph<Integer>(edges, 5);
    WeightedGraph<Integer>.ShortestPathTree tree2 = 
      graph2.getShortestPath(3);
    tree2.printAllPaths();*/
                   
              /*     
                   java.io.PrintWriter output = new java.io.PrintWriter("DataExport");
                   
                   int numberOfVertices = vertices.length;
                   output.println(numberOfVertices);
                   for (int startingVertex = 0; startingVertex < numberOfVertices; startingVertex++) {
                     int count = 0;
                     for (int i = 0; i < edges.length; i++) {      
                       if (edges[i][0] == startingVertex && edges[i][0] < edges[i][1]) {
                         count++;
                         if (count == 1)
                           output.print(edges[i][0] + ", " + edges[i][1] + ", " + edges[i][2]);
                         else
                           output.print(" | " + edges[i][0] + ", " + edges[i][1] + ", " + edges[i][2]);
                       }
                     }
                     if (count > 0) output.println();
                   }
                     
                   System.out.println("Done!");
                   output.close();*/
  }
}
